package com.rm.wechatapp.common;

import lombok.Data;

@Data
public class Result<T> {
    private int code;     // 状态码（200=成功，500=失败（服务器内部错误））
    private String msg;   // 提示信息
    private T data;       // 响应数据

    // 成功（无数据)
    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }

    // 成功（有数据）
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    // 失败
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.setCode(500);
        result.setMsg(msg);
        return result;
    }
}